<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
	session_start();
	require("dbfunc.php");
	require("datefunc.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>BINDER - KONTEN</title>
		<link rel="stylesheet" type="text/css" href="style2.css" title="style2" />
		<script type="text/javascript" src="script.js"></script>
		<script type="text/javascript" src="like.js"></script>
	</head>
	<body>
		<div id="wrapper">
			<div id="header"><? include('header.php'); ?></div>
			<div id="main">
				<div id="konten">
					<div class="atas">
					</div>
					<div class="tengah">
					<?php
						$judul=$_GET['jd'];
						$qres = mysql_query("SELECT * FROM konten WHERE judul = '$judul'");
						$row = mysql_fetch_array($qres);
						echo "<div class='judul' id='judul-isi'>";
							echo $row['judul'];
						echo "</div>";
						echo "<div class='isi'>";
							$tipe=$row['tipe'];
							switch ($tipe){
								case 1:	//link
									echo "<div class='isi-link'><a href='".$row['url']."'>Lihat link terkait</a></div>";
									echo "<br />Penjelasan :";
									echo "<div class='isi-about'>".$row['about']."</div>";
									break;
								case 2:	//gambar
									echo "<div class='isi-gambar'><img class='content-img' src='konten/".$row['judul'].".jpg' alt='".$row['judul']."' /></div>";
									break;
								case 3:	//video
									echo "<iframe allowfullscreen='' width='310' height='225' frameborder='0' src='".$row['url']."'></iframe>";
									break;
								default:
									break;
							}
						echo "</div>";
						echo "<div class='detail'>";
							echo "<div class='byon'>";
								echo "Dipost oleh <strong><span class='by'><a href='profile.php?uid=".$row['userpost']."'>".$row['userpost']."</a></span></strong> pada <strong>".diffDate($row['tgl'],date('d-m-Y H:i:s'))."</strong>";
							echo "</div>";
							echo "<div class='likedislike'>";
								echo "<ul class='ldbuttons'>";
									if (isset($_SESSION['username'])){
										if(strcmp($_SESSION['username'],$row['userpost'])!=0){
										$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$_SESSION['username']."'");
								if (mysql_num_rows($result)>0){
									//sudah like/dislike
									$baris = mysql_fetch_array($result);
									if ($baris['jenis']==1){	//like
										echo "<li class='islike' id='blike".$row['id']."'><a href=\"javascript:like(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
										echo "<li class='notdislike' id='bdislike".$row['id']."'></li>";
									}else{
										//dislike
										echo "<li class='notlike' id='blike".$row['id']."'></li>";
										echo "<li class='isdislike' id='bdislike".$row['id']."'><a href=\"javascript:dislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									}
								}else{
									//bisa like/dislike
									echo "<li class='like' id='blike".$row['id']."'><a href=\"javascript:like(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									echo "<li class='dislike' id='bdislike".$row['id']."'><a href=\"javascript:dislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
								}
										}else{
											$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$row['userpost']."'");
											if (mysql_num_rows($result)>0){
												//sudah like/dislike
												$baris = mysql_fetch_array($result);
												if ($baris['jenis']==1){	//like
													echo "<li class='islike' id='blike".$row['id']."'><a href=\"javascript:like(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
													echo "<li class='notdislike' id='bdislike".$row['id']."'></li>";
												}else{
													//dislike
													echo "<li class='notlike' id='blike".$row['id']."'></li>";
													echo "<li class='isdislike' id='bdislike".$row['id']."'><a href=\"javascript:dislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
												}
											}else{
												//bisa like/dislike
												echo "<li class='like' id='blike".$row['id']."'><a href=\"javascript:like(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
												echo "<li class='dislike' id='bdislike".$row['id']."'><a href=\"javascript:dislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
											}
										}
									}else{
										//tidak bisa apa-apa
										echo "<li class='like' id='blike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
										echo "<li class='dislike' id='bdislike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
									}
								echo "</ul>";
							echo "</div>";
							echo "<div class='count'>";
								echo "<strong><span id='jmllike".$row['id']."'>".$row['jmlLike']."</span></strong> user menyukai";
							echo "</div>";
							echo "<div class='count'>";
								echo "Tagged : <strong><span>".$row['tag']."</span></strong>";
							echo "</div>";
						echo "</div>";
						echo "<div class='komen'>";
							echo "<div class='komenjudul'>Comments</div>";
							echo "<div id='konten-commenter'>";
								echo "<strong><span id='jmlkomen'>".$row['jmlKom']."</span></strong> komentar";
							echo "</div>";
							echo "<div class='line-konten'></div>";
							echo "<div id='lkomen'>";
								$id = $row['id'];
								$sres = mysql_query("SELECT * FROM komentar WHERE konten_id = '$id' ORDER BY tgl DESC");
								while ($brow = mysql_fetch_array($sres)){
									echo "<div id='komen".$brow['id']."'>";
										if (isset($_SESSION['username'])){
											if (strcmp($_SESSION['username'],$brow['username'])==0)
												echo "<div class='komen-hapus'><a href=\"javascript:deleting(".$brow['id'].",'".$_SESSION['username']."')\">(X)</a></div>";
										}
										echo "<div class='komen-ava'><img class='komen-img' src=\"ava/".$brow['username'].".jpg\" /></div>";
										echo "<div class='komen-nama'><a href=\"profile.php?uid=".$brow['username']."\">".$brow['username']."</a></div>";
										echo "<div class='komen-tanggal'>".diffDate($brow['tgl'],date('d-m-Y H:i:s'))."</div>";
										echo "<div class='komen-isi'>".$brow['isi']."</div>";
										echo "<div class='line-konten'></div>";
									echo "</div>";
								}
							echo "</div>";
							if(isset($_SESSION['username'])){
								echo "<form action='' method='get' onsubmit=\"alert('komen')\">";
									echo "<div id='komen-tulis'><strong>Tulis Komentar</strong></div>";
									echo "<div class='clear'></div>";
									echo "<div class='komen-label btg-mrh' id='komen-btg'>*) wajib diisi</div>";
									echo "<div class='clear'></div>";
									echo "<div class='komen-label'>Komentar <span class='btg-mrh'>*</span></div><div class='register-td'>:</div><div class='register-input'><textarea name='komentar' rows='5' cols='78' id='form-komen'></textarea></div>";
									echo "<div class='clear'></div>";
									echo "<div class='komen-submit'><input class='btn' type='button' name='submit' onclick=\"commenting(".$row['id'].",'".$_SESSION['username']."')\" value='Post Comment!' /></div>";
								echo "</form>";
							}
				?>
						</div>
					</div>
					<div class="bawah">
					</div>
				</div>
				<div id="sidebar">
					<div class="iklan">
						<div id="adsay"><em>Advertisement</em></div>
						<a href="http://www.marlboro.com/"><img src="images/iklan-satu.jpg" alt="iklan 1" /></a>
					</div>
				</div>
			</div>
			<div id="footer"><? include('footer.php'); ?></div>
		</div>
		<script type="text/javascript" src="konten.js"></script>
	</body>
</html>